package com.bdqn.tour.dao.impl;

import com.bdqn.tour.dao.BaseDao;
import com.bdqn.tour.dao.GyhLoginDao;
import com.bdqn.tour.pojo.User;

import java.sql.SQLException;

/**
 * 登录信息实现类
 */
public class GyhLoginDaoImpl extends BaseDao implements GyhLoginDao {
    /**
     * 登录方法
     * @param phone 手机号码
     * @return 返回user对象
     */
    @Override
    public User getLogin(String phone) {
        //定义返回对象
        User user = null;
        //获取连接对象
        conn = this.getConnection();
        //编写sql
        String sql = "select id,username,ipone,password,nickname,email,sex,career,qq,status from user where ipone = ?";
        try {
            //4.预编译sql
            rs = this.executeQuery(sql,phone);
            //7.解析结果集
            while(rs.next()){
                user = new User();
                user.setId(rs.getInt(1));
                user.setUsername(rs.getString(2));
                user.setIpone(rs.getString(3));
                user.setPassword(rs.getString(4));
                user.setNickname(rs.getString(5));
                user.setEmail(rs.getString(6));
                user.setSex(rs.getString(7));
                user.setCareer(rs.getString(8));
                user.setQq(rs.getString(9));
                user.setStatus(rs.getString(10));
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            //释放资源
            this.closeAll(conn,psmt,rs);
        }

        return user;
    }

    @Override
    public User getLoginCheck(String phone) {
        //定义返回对象
        User user = null;
        //获取连接对象
        conn = this.getConnection();
        //编写sql
        String sql = "select id,username,ipone,password,nickname,email,sex,career,qq,status from user where ipone = ?";
        try {
            //4.预编译sql
            rs = this.executeQuery(sql,phone);
            //7.解析结果集
            while(rs.next()){
                user = new User();
                user.setId(rs.getInt(1));
                user.setUsername(rs.getString(2));
                user.setIpone(rs.getString(3));
                user.setPassword(rs.getString(4));
                user.setNickname(rs.getString(5));
                user.setEmail(rs.getString(6));
                user.setSex(rs.getString(7));
                user.setCareer(rs.getString(8));
                user.setQq(rs.getString(9));
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            //释放资源
            this.closeAll(conn,psmt,rs);
        }

        return user;
    }
}
